////////////////////////////////////////////////////////////////////////////
//
//  CryEngine Source File.
//  Copyright (C), Crytek, 1999-2011.
// -------------------------------------------------------------------------
//  File name:   IXmlHistoryManager.h
//  Version:     v1.00
//  Created:     16/03/2011 by Paul Reindell
//  Description: 
// -------------------------------------------------------------------------
//  History:
////////////////////////////////////////////////////////////////////////////

#ifndef __IXmlHistoryManager_H__
#define __IXmlHistoryManager_H__

// Helper class to handle Redo/Undo on set of Xml nodes
struct IXmlUndoEventHandler
{
	virtual bool SaveToXml( XmlNodeRef& xmlNode ) = 0;
	virtual bool LoadFromXml( const XmlNodeRef& xmlNode ) = 0;
	virtual bool ReloadFromXml( const XmlNodeRef& xmlNode ) = 0;
};

struct IXmlHistoryEventListener
{
	enum EHistoryEventType
	{
		eHET_HistoryDeleted,
		eHET_HistoryCleared,
		eHET_HistorySaved,

		eHET_VersionChanged,
		eHET_VersionAdded,

		eHET_HistoryInvalidate,

		eHET_HistoryGroupChanged,
		eHET_HistoryGroupAdded,
		eHET_HistoryGroupRemoved,
	};
	virtual void OnEvent( EHistoryEventType event, void* pData = NULL ) = 0;
};

struct IXmlHistoryView
{
	virtual bool LoadXml( int typeId, const XmlNodeRef& xmlNode, IXmlUndoEventHandler*& pUndoEventHandler, uint32 userindex ) = 0;
	virtual void UnloadXml( int typeId ) = 0;
};

struct IXmlHistoryManager
{
	// Undo/Redo
	virtual bool Undo() = 0;
	virtual bool Redo() = 0;
	virtual bool Goto( int historyNum ) = 0;
	virtual void RecordUndo( IXmlUndoEventHandler* pEventHandler, const char* desc ) = 0;
	virtual void UndoEventHandlerDestroyed( IXmlUndoEventHandler* pEventHandler, uint32 typeId = 0, bool destoryForever = false ) = 0;
	virtual void RestoreUndoEventHandler( IXmlUndoEventHandler* pEventHandler, uint32 typeId ) = 0;

	virtual void RegisterEventListener( IXmlHistoryEventListener* pEventListener ) = 0;
	virtual void UnregisterEventListener( IXmlHistoryEventListener* pEventListener ) = 0;

	// History
	virtual void ClearHistory(bool flagAsSaved = false) = 0;
	virtual int GetVersionCount() const = 0;
	virtual const string& GetVersionDesc( int number ) const = 0;
	virtual int GetCurrentVersionNumber() const = 0;

	// Views
	virtual void RegisterView( IXmlHistoryView* pView ) = 0;
	virtual void UnregisterView( IXmlHistoryView* pView ) = 0;
};

#endif